/**
 *	流程模块接口文件：option数据选项
 *	开发者：雨中磐石
 *	地址：www.rockoa.com
 *	日期：2023-07-19
 */

package com.framework.Module.system.option;




import com.framerock.baselib.Json;
import com.framerock.baselib.Rock;
import com.framerock.baselib.Xinhu;
import com.framework.Flow.FlowListener;
import com.framework.Model.ModelOption;

import java.util.Map;


public class FlowListeneroption extends FlowListener {



    @Override
    public Boolean onModejs() {
        return true;
    }

    public Boolean onisDelete() {
        return true;
    }

    @Override
    public int onCompanymode() {
        return 3;
    }

    @Override
    public String onDeletebefore() {
        int to = mFlow.mModel.getCount("`pid`="+mFlow.mid+"");
        if(to>0)return "有下级不允许删除";
        return "";
    }

    public Map<String, String> onDatabefore(){
        int pid         = Integer.parseInt(mRequest.get("pid", "0"));
        String where    = "1=2";
        if(pid>0)where    = "`pid`="+pid+"";
        return Rock.getMap(new String[]{
                "where", where,
        });
    }

    public Map<String, String> onDataafter()
    {
        int loadci  = Integer.parseInt(mRequest.get("loadci", "1"));
        Map<String, String> da = Rock.getMap();
        if(loadci == 1){
            String otype = mRequest.get("otype"),pnum = "xinhu_"+mRequest.COMPANYID+"";
            if(Rock.isEmpt(otype))pnum = "xinhu";
            String pid = ModelOption.get(this.nDb).getVal(pnum, "-1", "id");
            da.put("optionarr", Json.getListString(mFlow.mModel.getAll("`pid` in("+pid+")", "`id`,`name`,`pid`", "`sort`")));
            da.put("firstid", pid);
        }
        return da;
    }

    @Override
    public Map<String, String> onReplacers(Map<String, String> da, int lx) {
        String id = da.get("id");
        int down   = mFlow.mModel.getCount("`pid`="+id+"");
        da.put("temp_down", down+"");
        return da;
    }

    @Override
    public void onCellEditAfter(String id, String fields, String value) {
        String num = mFlow.getFieldsval("num");
        if(!Rock.isEmpt(num)) Xinhu.setNull(num);
    }
}
